package com.easy.config;

import com.easy.interceptor.ShoppingLoginInterceptor;
import com.easy.interceptor.SystemLoginInterceptor;
import com.easy.util.SYS;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class EasyWebMVCConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //定义D://easyupload中的资源访问路径
        //让springmvc添加一个处理器,访问静态资源
        //浏览器访问 easyfile/文件名 就访问到下列的资源处理器
        registry.addResourceHandler(SYS.FILE_UPLOAD_URL+"/**").
                addResourceLocations("file:"+SYS.FILE_UPLOAD_DIR);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 前台购物系统的拦截器
        registry.addInterceptor(new ShoppingLoginInterceptor())
                .addPathPatterns("/shopping/cart","/cart/**","/shopping/personalinformation","/shopping/checkout","/shopping/orderdetails","/shopping/payment");

        // 后台管理系统的拦截器
        registry.addInterceptor(new SystemLoginInterceptor())
                .addPathPatterns("/system/**")  // 拦截后台管理相关的路径
                .excludePathPatterns("/system/login", "/system/dologin1");  // 排除登录相关路径
    }
}
